<?php

declare(strict_types=1);

namespace App\Robot\Amqp\Consumer;

use App\Robot\Service\SendRecordMessageHandlerService;
use Hyperf\Amqp\Annotation\Consumer;
use Hyperf\Amqp\Message\ConsumerMessage;
use Hyperf\Amqp\Result;
use PhpAmqpLib\Message\AMQPMessage;
use function Hyperf\Collection\data_get;

#[Consumer(exchange:"hyperf_exchange", routingKey:"hyperf_high_priority", queue:"hyperf_high_priority", name:"HighPriorityConsumer", nums:2)]
class HighPriorityRobotMsgConsumer extends ConsumerMessage
{
    public function consumeMessage($data, AMQPMessage $message): Result
    {
        // 判断是否需要延迟
        $messageData = data_get($data,'data',[]);
        if(empty($messageData)){
            return Result::DROP;
        }
        //立即发送
        container()->get(SendRecordMessageHandlerService::class)->handle($messageData);
        return Result::ACK;
    }


    public function isEnable(): bool
    {
        return \Hyperf\Support\env('AMQP_CONSUMER_ENABLE',false);
    }
}